<template>
  <sv-page showTabBar>
    <view class="hall sv-uv-vtabs">
      <uv-vtabs
        :list="professions"
        :hdHeight="vtabHeight.hdHeight"
        :height="vtabHeight.height"
        chain
        keyName="profession_name"
        @change="change"
      >
        <uv-vtabs-item v-for="(item, index) in professions" :key="index" :index="index">
          <view class="padding-lr padding-top text-bold text-lg">{{ item.profession_name }}</view>
          <view class="padding sv-grid grid-col-4 grid-gap-lg" v-if="item.lib?.length > 0">
            <view class="flex-col-vhc" v-for="it in item.lib" :key="it.lib_id" @click="onLib(it)">
              <view
                class="bg-gradual-blue lib-icon"
                :class="[it.icon, it.vip ? 'lib-icon-vip' : '']"
              ></view>
              <view class="margin-top-xs">{{ it.lib_name }}</view>
            </view>
          </view>
        </uv-vtabs-item>
      </uv-vtabs>
    </view>
  </sv-page>
</template>

<script setup>
import { computed, ref } from 'vue'
import { onLoad } from '@dcloudio/uni-app'
import { professionList } from '@/service/api/profession.js'

const vtabHeight = computed(() => {
  const { statusBarHeight, screenHeight, safeAreaInsets } = uni.getSystemInfoSync()
  return {
    height: screenHeight - statusBarHeight - safeAreaInsets.bottom - 44 - 50,
    hdHeight: statusBarHeight + 44
  }
})

onLoad(async () => {
  uni.showLoading({
    title: '加载中...',
  })
  await getProfessionList()
  uni.hideLoading()
})

const professions = ref([])
async function getProfessionList() {
  const professionRes = await professionList()
  professions.value = professionRes.data || []
}

function change(index) {
  console.log('选项改变：', index)
}

function onLib(e) {
  console.log('==== onLib :', e)
  uni.navigateTo({
    url: `/pages/lib-detail/lib-detail?lib_id=${e.lib_id}&lib_name=${e.lib_name}`
  })
}
</script>

<style lang="scss">
.hall {
  height: var(--page-main-height);

  .lib-icon {
    font-size: 80rpx;
    border-radius: 12rpx;
    padding: 10rpx;
    position: relative;
    overflow: hidden;

    &.lib-icon-vip::after {
      content: 'VIP';
      position: absolute;
      right: -24rpx;
      top: 0;
      font-size: 12px;
      width: 60rpx;
      height: 20rpx;
      text-align: center;
      background-color: #ffff0066;
      padding: 8rpx 12rpx;
      transform: rotate(45deg);
    }
  }
}
</style>
